import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {PolicySpecialService} from './policy-special.service';
import {Router} from '@angular/router';

@Component({
  selector: 'app-policy-special',
  templateUrl: './policy-special.component.html',
  styleUrls: ['./policy-special.component.less']
})
export class PolicySpecialComponent implements OnInit {
  topicsData = [];
  policyOfRegion = [];
  isSpinning;
  isChangeColor = [];
  @Output() specialName = new EventEmitter<string>();
  paramName: string;

  constructor(private specialSer: PolicySpecialService,
              private router: Router) {
  }

  ngOnInit(): void {
    this.getPolicyTopics();
  }

  getPolicyTopics() {
    this.isChangeColor[0] = true;
    this.isSpinning = true;
    this.specialSer.getPolicyTopics().subscribe(res => {
      this.topicsData = res.result;
      this.specialName.emit(res.result[0].name);
      this.paramName = res.result[0].name;
      for (let i = 0; i < res.result.length; i++) {
        this.policyOfRegion[i] = res.result[i].policyTopicsRegions[0]?.policy;
      }
      this.isSpinning = false;
    });
  }

  regionSelect(policyList?: any, index?: number) {
    this.policyOfRegion[index] = policyList;
  }

  toMoreList(id: number) {
    this.router.navigate(['/related-policy-list'], {queryParams: {wordFrameId: id}});

  }

  changeColor(index: number, specialName: string) {
    this.specialName.emit(specialName);
    this.paramName = specialName;
    for (let i = 0; i < this.topicsData.length; i++) {
      this.isChangeColor[i] = false;
    }
    this.isChangeColor[index] = true;
  }
}
